package com.matrix.demo;

import android.graphics.Matrix;

/**
 * Created by lgs on 2018/5/4.
 */

public class ViewPortHandler {

    /**
     * maximum scale value on the x-axis
     */
    private static float mMaxScaleX = Float.MAX_VALUE;

    private static Matrix mMatrixTouch = new Matrix();

    public static Matrix zoomIn(float x, float y) {
        Matrix save = new Matrix();
        zoomIn(x, y, save);
        return save;
    }

    private static void zoomIn(float x, float y, Matrix outputMatrix) {
        outputMatrix.reset();
        outputMatrix.set(mMatrixTouch);
        outputMatrix.postScale(1.4f, 1.4f, x, y);

    }

    public static Matrix zoomOut(float x, float y) {
        Matrix save = new Matrix();
        zoomOut(x, y, save);
        return save;
    }

    public static void zoomOut(float x, float y, Matrix outputMatrix) {
        outputMatrix.reset();
        outputMatrix.set(mMatrixTouch);
        outputMatrix.postScale(0.7f, 0.7f, x, y);
    }

    /**
     * 设置X轴最大限度缩放因子
     * @param xScale
     */
    public static void setMaximumScaleX(float xScale) {

        if(xScale == 0.f)
            xScale = Float.MAX_VALUE;

        mMaxScaleX = xScale;
    }
}
